/*
 *
 * ### 此文件用来引入工具类JS，进行测试 ###2
 *
 */

document.body.innerHTML=Module.badge("123","456789")
// Module.styleDebugConsole(".__YHBToolBadgeDiv")
const a = 6
const b = 2
//32768 16384 8192 4096 2048 1024 512 256 | 128 64 32 16 8 4 2 0
console.log(a+" 的二进制为 = "+(a.toString(2)));
console.log(b+" 的二进制为 = "+(b.toString(2)));
console.log(`${a}|${b} 或运算 = `+(a|b));
console.log(`${a}&${b} 与运算 = `+(a&b));
console.log(`${a}^${b} 异或运算 = `+(a^b));
console.log(`${a}>>${b} 右移运算 = `+(a>>b));
console.log(`${a}<<${b} 左移运算 = `+(a<<b));
console.log(`${a}>>>${b} 全右移(无符号右移)运算 = `+(a>>>b));
console.log(`~${a} 取反运算 = `+(~a));
console.log(`~${b} 取反运算 = `+(~b));
// const newArr = [
//   { num: 2, age: 5, in: 6, name: 'aa' },
//   { num: 3, age: 5, in: 6, name: 'bb' },
//   { num: 4, age: 5, in: 6, name: 'cc' },
//   { num: 5, age: 5, in: 6, name: 'dd' },
//   { num: 6, age: 5, in: 6, name: 'ee' },
//   { num: 7, age: 5, in: 6, name: 'ff' },
//   { num: 8, age: 5, in: 6, name: 'gg' },
// ]

console.log("====================================");
/*  */
function DeepOperation(data) {
  return new Deep(data)
}
class Deep { 
  constructor(data) { 
    //原数据
    this.value = data
    //类型
    const Type = Object.prototype.toString.call(data)
    //具体类型
    this.Type = Type
    //抽离类型
    this.type = Type.substring(Type.indexOf(" ")+1,Type.length-1)
    //JSON
    this.JSON = JSON.stringify(data)
    //字符串
    this.String = data.toString()
    //长度 & 数组 & 对象
    this.Object = {}
    if (Type === "[object Array]") {
      this.length = data.length
      this.Array = []
      data.forEach((item, index) => {
        this.Array.push(item)
        this.Object[index] = item
      })
    } else if (Type === "[object Object]") {
      let num = 0
      this.Array = []
      for (const key in data) {
        if (Object.hasOwnProperty.call(data, key)) {
          this.Array.push(data[key])
          this.Object[key] = data[key]
          num++
        }
      }
      this.length = num
    } else if (Type === "[object Number]") {
      this.length = String(data).length
      this.Array = String(data).split("")
      this.Array.forEach((item,index) => { 
        this.Object[index] = item
      })
    } else { 
      this.length = 1
      this.Array = new Array(data)
      this.Array.forEach((item,index) => { 
        this.Object[index] = item
      })
    }
    //遍历函数
    this.for = function (callback) {
      let tempData = data
      if (Type!=="[object Array]"&&Type!=="[object Object]") { 
        if(Type==="[object Number]")tempData = String(tempData).split("")
        else tempData = new Array(tempData)
      }
      let index = 0
      for (const key in tempData) {
        if (Object.hasOwnProperty.call(tempData, key)) {
          callback(tempData[key], key, index)
          index++
        }
      }
    }
    /* 预设
      Hax，每种类型特有方法，md5
    */
  }
}
/* const d = DeepOperation(true)
d.for((item,key,index) => { 
  console.log(item);
  console.log(key);
  console.log(index);
})
console.log("-------------------");
console.log(d.length);
console.log(d.Type);
console.log(d.type);
console.log(d.value);
console.log(d.String);
console.log(d.Array);
console.dir(d.Object);
console.dir(d.JSON);
console.log("-------------------");
console.dir(d); */
// console.log(DeepOperation(123));
// console.log(DeepOperation("abc"));
// console.log(DeepOperation(true));
// console.log(DeepOperation([7,8,9]));
// console.log(DeepOperation({name:"张三",age:28}));
// console.log(DeepOperation(null));
// console.log(DeepOperation(NaN));
// console.log(DeepOperation(undefined));